package com.hanbang.gycatering.aboutme;

import org.json.JSONException;
import org.json.JSONObject;

import com.hanbang.gangyu.R;
import com.hanbang.gycatering.application.MyApplication;
import com.hanbang.gycatering.homepage.BaseActivity;
import com.hanbang.gycatering.property.AnnouncementDetail;
import com.hanbang.gycatering.utils.HttpInterfaces;
import com.hanbang.gycatering.utils.MyLog;
import com.hanbang.gycatering.utils.MyRequestCallBack;
import com.hanbang.gycatering.utils.MyToast;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class FeedDetail extends BaseActivity implements OnClickListener {
	private int feedbackId;
	private boolean replystate;
	private TextView feeddetail_content,feed_time,
			reply_time;
	private WebView feeddetail_reply;
	private LinearLayout ll_reply;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feed_detail);
		initView();
	}

	private void initView() {
		// TODO Auto-generated method stub
		((TextView) findViewById(R.id.top_bar_title)).setText("意见详情");
		setBackArrows((ImageView) findViewById(R.id.top_bar_left_image));
		ll_reply = (LinearLayout) findViewById(R.id.ll_reply);
		feeddetail_content = (TextView) findViewById(R.id.feeddetail_content);
		feeddetail_reply = (WebView) findViewById(R.id.feeddetail_reply);
		WebSettings settings = feeddetail_reply.getSettings(); 
		settings.setDefaultFontSize(14);
		feed_time = (TextView) findViewById(R.id.feed_time);
		reply_time = (TextView) findViewById(R.id.reply_time);
		Intent intent = getIntent();
		feedbackId = intent.getIntExtra("feedbackId", 0);
		replystate=intent.getBooleanExtra("replystate", false);
		getFeedDetailData();
	}

	private void getFeedDetailData() {
		// TODO Auto-generated method stub
		((MyApplication) getApplicationContext()).httpUtils
				.send(HttpMethod.GET, HttpInterfaces.feeddetails
						+ "&userphone=" + userData.getUserphone()
						+ "&password=" + userData.getUserpassword()
						+ "&leaveid=" + feedbackId,
						new MyRequestCallBack<String>(FeedDetail.this,
								getString(R.string.loadding)) {
							@Override
							public void onSuccess(
									ResponseInfo<String> responseInfo) {
								super.onSuccess(responseInfo);
								try {
									JSONObject json = new JSONObject(
											responseInfo.result);
									if (json.getInt("state") == 1) {
										JSONObject infor = json
												.getJSONObject("info");
										feeddetail_content.setText(infor
												.getString("lcontent"));
										MyLog.e("hehehehhehe", infor
												.getString("lcontent"));
										feed_time.setText(infor
												.getString("ltime"));
										if (replystate) {
											ll_reply.setVisibility(View.VISIBLE);
											feeddetail_reply.loadDataWithBaseURL(null, infor
													.getString("rcontent"), "text/html",
													"utf-8", null); 
											reply_time.setText(infor
													.getString("rtime"));
										}
									} else {
										MyToast.show(FeedDetail.this, "获取数据失败",
												Toast.LENGTH_SHORT);
									}
								} catch (JSONException e) {
									e.printStackTrace();
									MyToast.show(FeedDetail.this, "获取数据失败1",
											Toast.LENGTH_SHORT);
								}
							}
						});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {

		default:
			break;
		}
	}
}
